package src.view;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.RemoteException;

import javax.swing.*;

import src.controller.AddUserController;
import src.resource.PublicResource;



import com.jgoodies.forms.layout.*;
/*
 * Created by JFormDesigner on Sun May 23 13:46:10 ART 2010
 */



/**
 * @author Guillermo Exposito
 */
public class AddUser extends JPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private AddUserController controller;
	private static AddUser instance=null;
	private final String  PATH=PublicResource.getPath();
	
	
	
	private AddUser(AddUserController controller) {
		this.controller=controller;
		initComponents();
		this.btnSave.addActionListener(new ActionSaveUser());
	}
	
	public static AddUser getInstance(AddUserController controller){
		if(instance==null)
			instance=new AddUser(controller);
		return instance;
	}
	
	

	private void initComponents() {
		// JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
		// Generated using JFormDesigner Evaluation license - Guillermo Exposito
		jPanelFields = new JPanel();
		lblTitle = new JLabel();
		lblName = new JLabel();
		txtName = new JTextField();
		label3 = new JLabel();
		lblUserName = new JLabel();
		txtUserName = new JTextField();
		label4 = new JLabel();
		lblCountry = new JLabel();
		txtCountry = new JTextField();
		lblCity = new JLabel();
		txtCity = new JTextField();
		lblAddress = new JLabel();
		txtAddress = new JTextField();
		lblPhoneNumber = new JLabel();
		txtPhoneNumber = new JTextField();
		label1 = new JLabel();
		chkActive = new JCheckBox();
		label2 = new JLabel();
		btnSave = new JButton();
		CellConstraints cc = new CellConstraints();

		//======== this ========

		
		setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

		//======== jPanelFields ========
		{
			jPanelFields.setLayout(new FormLayout(
				"10dlu, $lcgap, 60dlu, $lcgap, 150dlu, 5dlu, 10dlu",
				"10dlu, $lgap, default, 5dlu, 7*($lgap, default), $lgap, 10dlu, $lgap, default, $lgap, 10dlu"));

			//---- lblTitle ----
			lblTitle.setText("Add user");
			lblTitle.setHorizontalAlignment(SwingConstants.LEFT);
			lblTitle.setFont(new Font("Dialog", Font.PLAIN, 18));
			jPanelFields.add(lblTitle, cc.xywh(1, 3, 7, 1, CellConstraints.CENTER, CellConstraints.DEFAULT));

			//---- lblName ----
			lblName.setText("Name");
			lblName.setHorizontalAlignment(SwingConstants.RIGHT);
			jPanelFields.add(lblName, cc.xy(3, 6));
			jPanelFields.add(txtName, cc.xy(5, 6));

			//---- label3 ----
			label3.setText("*");
			label3.setForeground(Color.red);
			jPanelFields.add(label3, cc.xy(6, 6));

			//---- lblUserName ----
			lblUserName.setText("User name");
			lblUserName.setHorizontalAlignment(SwingConstants.RIGHT);
			jPanelFields.add(lblUserName, cc.xy(3, 8));
			jPanelFields.add(txtUserName, cc.xy(5, 8));

			//---- label4 ----
			label4.setText("*");
			label4.setForeground(Color.red);
			jPanelFields.add(label4, cc.xy(6, 8));

			//---- lblCountry ----
			lblCountry.setText("Country");
			lblCountry.setHorizontalAlignment(SwingConstants.RIGHT);
			jPanelFields.add(lblCountry, cc.xy(3, 10));
			jPanelFields.add(txtCountry, cc.xy(5, 10));

			//---- lblCity ----
			lblCity.setText("City");
			lblCity.setHorizontalAlignment(SwingConstants.RIGHT);
			jPanelFields.add(lblCity, cc.xy(3, 12));
			jPanelFields.add(txtCity, cc.xy(5, 12));

			//---- lblAddress ----
			lblAddress.setText("Address");
			lblAddress.setHorizontalAlignment(SwingConstants.RIGHT);
			jPanelFields.add(lblAddress, cc.xy(3, 14));
			jPanelFields.add(txtAddress, cc.xy(5, 14));

			//---- lblPhoneNumber ----
			lblPhoneNumber.setText("Phone number");
			lblPhoneNumber.setHorizontalAlignment(SwingConstants.RIGHT);
			jPanelFields.add(lblPhoneNumber, cc.xy(3, 16));
			jPanelFields.add(txtPhoneNumber, cc.xy(5, 16));

			//---- label1 ----
			label1.setText("State");
			jPanelFields.add(label1, cc.xywh(3, 18, 1, 1, CellConstraints.RIGHT, CellConstraints.DEFAULT));

			//---- chkActive ----
			chkActive.setText("active");
			jPanelFields.add(chkActive, cc.xy(5, 18));

			//---- label2 ----
			label2.setText("* Required fields");
			label2.setForeground(Color.red);
			jPanelFields.add(label2, cc.xy(5, 20));

			//---- btnSave ----
			btnSave.setText("Save");
			jPanelFields.add(btnSave, cc.xywh(5, 22, 1, 1, CellConstraints.RIGHT, CellConstraints.DEFAULT));
		}
		add(jPanelFields);
		// JFormDesigner - End of component initialization  //GEN-END:initComponents
		
		lblTitle.setIcon(new ImageIcon(PATH+"contact-new.png"));
		btnSave.setIcon(new ImageIcon(PATH+"document-save.png"));
		
	}

	// JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
	// Generated using JFormDesigner Evaluation license - Guillermo Exposito
	private JPanel jPanelFields;
	private JLabel lblTitle;
	private JLabel lblName;
	private JTextField txtName;
	private JLabel lblUserName;
	private JTextField txtUserName;
	private JLabel lblCountry;
	private JTextField txtCountry;
	private JLabel lblCity;
	private JTextField txtCity;
	private JLabel lblAddress;
	private JTextField txtAddress;
	private JLabel lblPhoneNumber;
	private JTextField txtPhoneNumber;
	private JButton btnSave;
	private JLabel label1;
	private JCheckBox chkActive;
	private JLabel label3;
	private JLabel label2;
	private JLabel label4;
	// JFormDesigner - End of variables declaration  //GEN-END:variables


	public JButton getBtnSave() {
		return btnSave;
	}

	public void setBtnSave(JButton btnSave) {
		this.btnSave = btnSave;
	}

	public JTextField getTxtName() {
		return txtName;
	}

	public void setTxtName(JTextField txtName) {
		this.txtName = txtName;
	}

	public JTextField getTxtUserName() {
		return txtUserName;
	}

	public void setTxtUserName(JTextField txtUserName) {
		this.txtUserName = txtUserName;
	}

	public JTextField getTxtCountry() {
		return txtCountry;
	}

	public void setTxtCountry(JTextField txtCountry) {
		this.txtCountry = txtCountry;
	}

	public JTextField getTxtCity() {
		return txtCity;
	}

	public void setTxtCity(JTextField txtCity) {
		this.txtCity = txtCity;
	}

	public JTextField getTxtAddress() {
		return txtAddress;
	}

	public void setTxtAddress(JTextField txtAddress) {
		this.txtAddress = txtAddress;
	}

	public JTextField getTxtPhoneNumber() {
		return txtPhoneNumber;
	}

	public void setTxtPhoneNumber(JTextField txtPhoneNumber) {
		this.txtPhoneNumber = txtPhoneNumber;
	}

	public JCheckBox getChkActive() {
		return chkActive;
	}

	public void setChkActive(JCheckBox chkActive) {
		this.chkActive = chkActive;
	}
	
	private class ActionSaveUser implements ActionListener {
		public void actionPerformed(ActionEvent e) {

			try {
				controller.performSaveUser();
				//DialogResource.showSaveSucessfully(btnSave.getLocation());
				
			} catch (RemoteException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}

		}
	}
	
	
	
	
	
}